<template>
  <div class="app-container">
    <div class="app-title">
      <span>人员变动审核</span>
    </div>
    <el-row :gutter="20">
      <el-col :span="8">
        <el-col :span="1">
          <i :class="[treeShow ? 'el-icon-s-fold treeI' : 'el-icon-s-unfold treeI']" @click="toggerTree" />
        </el-col>
        <div class="tap-fillet">
          <el-radio-group v-model="activeName" style="margin-left:4rem; width:700px; height:15px; margin-top:-57px">
            <el-radio-button label="1" name="isNoAudit">未审核</el-radio-button>
            <el-radio-button label="2" name="isIsAudit">已审核</el-radio-button>
            <el-radio-button label="auditAll" name="isAuditAll">全部</el-radio-button>
          </el-radio-group>
        </div>
      </el-col>
      <div class="filter-container">
        <div class="longbuton">
          <el-col style="text-align:right;margin-top:-3px;" :span="16">
            <el-button size="small" class="filter-item" style="margin-left:10px;" type="primary" @click="Query">
              查询
            </el-button>
            <el-button v-if="activeName === '1'" size="small" class="filter-item" style="margin-left:10px;"
              type="primary" :loading="approvedLoading" @click="personApproved">
              审核
            </el-button>
            <el-button v-if="activeName === '1'" size="small" class="filter-item" style="margin-left:10px;"
              type="primary" :loading="rejectLoading" @click="rejectOperate">
              退回
            </el-button>
            <!-- <el-button
              v-if="activeName === '1'"
              size="small"
              class="filter-item"
              style="margin-left:10px;"
              type="primary"
            >
              撤销退回
            </el-button> -->
            <el-button v-if="activeName === '2'" size="small" class="filter-item" style="margin-left:10px;"
              type="primary" :loading="revokeLoading" @click="rejectPersonApproved">
              撤销审核
            </el-button>
            <el-button size="small" class="filter-item" style="margin-left:10px;" type="primary" @click="appendixOpen">
              附件管理
            </el-button>
          </el-col>
        </div>
      </div>
      <!-- 图标 -->
      <div>
        <div style="margin-left:266px; position:absolute; margin-top:-1px">
          <img style="width:16px; height:16px;" :src="allimgSrc">
        </div>
        <div style="margin-left:88px; position:absolute; margin-top:-1px">
          <img style="width:16px; height:16px;" :src="Processedimg">
        </div>
        <div style="margin-left:178px; position:absolute; margin-top:-1px">
          <img style="width:16px; height:16px;" :src="Untreatedimg">
        </div>
      </div>
    </el-row>

    <div class="grid-content bg-purple" />

    <div ref="box" class="box">
      <div class="left" :class="[isActive ? 'wid' : 'wids']">
        <div :class="[treeShow ? 'treeShow' : 'treeNotShow']" :style="{ 'height': treeHeight + 'px' }">
          <AgencyTree class="agencyTree" @handleTreeQuery="handleTreeQuery"
            @getFirstAuthAgencyData="getFirstAuthAgencyData" />
        </div>
      </div>
      <div v-show="Show" class="resize" title="收缩侧边栏" />
      <div class="mid" :class="[isActive ? 'mids' : 'min']">
        <personChangeAuditChildrenTable :key="timer" ref="chil" :tree-data="treeData" :tab-pane="activeName"
          @approvedCallback="approvedCallback" @rejectCallback="rejectCallback"
          @rejectPersonApprovedCallback="rejectPersonApprovedCallback" />
      </div>
      <Drag ref="icon" />
    </div>
  </div>
</template>

<script>
import personChangeAuditChildrenTable from '@/views/personInfoMaintenance/children/personChangeAuditChildren'
import AgencyTree from '@/components/tree/agencyTree'
import Drag from '@/components/Drag'

export default {
  name: 'PersonChangeAudit',
  components: { personChangeAuditChildrenTable, AgencyTree, Drag },
  data() {
    return {
      treeHeight: null,
      isActive: true,
      Show: false,
      treeShow: false,
      treeData: '',
      timer: '',
      activeName: '1',
      approvedLoading: false,
      rejectLoading: false,
      rejectPersonApprovedLoading: false,
      allimgSrc: require('@/assets/images/all.png'),
      Processedimg: require('@/assets/images/select.png'),
      Untreatedimg: require('@/assets/images/processed.png')
    }
  },
  // 图片显示
  watch: {
    activeName(val) {
      this.timer = new Date().getTime()
      if (val === 'auditAll') {
        this.allimgSrc = require('@/assets/images/whiteall.png')
        this.Processedimg = require('@/assets/images/blueselect.png')
        this.Untreatedimg = require('@/assets/images/processed.png')
      } else if (val === '1') {
        this.allimgSrc = require('@/assets/images/all.png')
        this.Processedimg = require('@/assets/images/select.png')
        this.Untreatedimg = require('@/assets/images/processed.png')
      } else {
        this.allimgSrc = require('@/assets/images/all.png')
        this.Processedimg = require('@/assets/images/blueselect.png')
        this.Untreatedimg = require('@/assets/images/blue.png')
      }
    }
  },
  created() { },
  mounted() {
    this.dragController()
    this.getTeHeight()
  },
  beforeMount() {
    window.addEventListener('resize', this.getTeHeight)
  },
  methods: {
    getFirstAuthAgencyData(data) {
      this.treeData = data
    },
    getTeHeight() {
      this.treeHeight = window.innerHeight - 213
    },
    // 拖拽
    dragController() {
      this.$refs.icon.dragControllerDiv()
    },
    toggerTree() {
      this.treeShow = !this.treeShow
      this.isActive = !this.isActive
      this.Show = !this.Show
    },
    handleTreeQuery(data) {
      if (data && data.isleaf === '1') {
        this.treeData = data
      }
    },
    // 查询
    Query() {
      if (this.treeData && this.treeData.isleaf === '1') {
        this.$refs.chil.query()
      }
    },
    // 审核
    personApproved() {
      if (this.treeData && this.treeData.isleaf === '1') {
        this.approvedLoading = true
        this.$refs.chil.personApproved()
      }
    },
    // 退回
    rejectOperate() {
      if (this.treeData && this.treeData.isleaf === '1') {
        this.rejectLoading = true
        this.$refs.chil.rejectOperate()
      }
    },
    // 撤销审核
    // revokeVerify() {
    //   this.revokeLoading = true
    //   this.$refs.chil.revokeVerify()
    // },
    // 审核通过回调
    approvedCallback() {
      this.approvedLoading = !this.approvedLoading
    },
    // 退回回调
    rejectCallback() {
      this.rejectLoading = !this.rejectLoading
    },
    // 撤销审核
    rejectPersonApproved() {
      if (this.treeData && this.treeData.isleaf === '1') {
        this.rejectPersonApprovedLoading = true
        this.$refs.chil.rejectPersonApproved()
      }
    },
    // 撤销审核回调
    rejectPersonApprovedCallback() {
      this.rejectPersonApprovedLoading = false
    },
    // 打开弹窗
    appendixOpen() {
      if (this.treeData && this.treeData.isleaf === '1') {
        this.$refs.chil.appendixOpen()
      }
    }
  }
}
</script>
<style lang="scss" scoped>
@import "~@/styles/border.scss";

/*引入公共样式*/
.el-col-5 {
  width: 50%;
}

.el-radio-button:last-child .el-radio-button__inner {
  border-radius: 0 10px 0 0;
}

.el-radio-button:first-child .el-radio-button__inner {
  border-radius: 0 0 0 10px;
}
</style>
